package com.kotlin.demo

import java.lang.Exception
import java.lang.IllegalArgumentException

fun main() {
    var name: String = "zq"
//    name = null
    println(name.capitalize())

    var name2: String?
    name2 = null
    println(name2)


    //使用带着 let的安全调用

    var name3: String?
    name3 = null
    name3 = "zq"
    name3 = ""
    val aaa = name3?.let {
        if (name3.isBlank()) {
            "default"
        } else {
            "[$it]"
        }
    }

    println(aaa)

    //kotlin 空合并操作符  ?:
    var info: String? = "李小龙"
    info = null
    println(info ?: "原来你是null ")

    println(info.let { "[$it]" } ?: "原来你是null")


    //自定义异常
    try {
        var excp: String? = null
        excp = null
        checkException(info)
//        println(excp!!.length)
    } catch (e: Exception) {
        println("啊呀 ${e.toString()}")
    }


}

fun checkException(info: Nothing?) {
    info ?: throw CustomException()
}

class CustomException() : IllegalArgumentException("你的代码太不严谨了")
